<!DOCTYPE html>
<html>
<head>@ include("/weixin/include/header.html",{"title":"通讯录"}){}
</head>
<body>
	<div class="tree" style="margin-top: 14px" id="tree"></div>
	@ include("/weixin/include/js_import.html"){}
	<script type="text/javascript">
		var nodeData = [
						
@  for(node in nodeList){
					{"id":"${node.id}","name":"${node.name}","pid":["${node.pid}"],"type":"${node.type}"},
@  }
		];
	
		$(function() {
			initNodes();
		});
		
		function aClick(icon,e){
			if(e != undefined){
				e.stopPropagation();
			}
			var item = $(icon).parent();
			if(item.hasClass("active")){
				item.removeClass("active");
				item.siblings().toggle();
			}else{
				item.addClass("active");
				item.siblings().toggle();
			}
			
		}
		
		
		function rowClick(id,e){
			e.stopPropagation();
			window.location.href="${basePath}/weixinContact/personList?id="+id;
			
		}
		
		function initNodes(){
			var tree = $("#tree");
			console.log(tree);
			for(var i in nodeData){
				var item = nodeData[i];
				console.log(item);
				if(item.type=="1"){
					tree.append("<div class='contactbook_row' id='"+item.type+"_"+item.id+"'><div class='contact_item'  onclick='rowClick("+item.id+",event)'><a onclick='aClick(this,event)'>"+item.name+"</a></div></div>");
							
				}else if(item.type=="2"){
					tree.append("<div class='contactbook_row' id='"+item.type+"_"+item.id+"'><div class='contact_item'  onclick='rowClick("+item.id+",event)'><a onclick='aClick(this,event)'>"+item.name+"</a></div></div>");
							
				}else if(item.type=="3"){
					tree.append("<div class='contactbook_row' id='"+item.type+"_"+item.id+"'><div class='contact_item'  onclick='rowClick("+item.id+",event)'><a onclick='aClick(this,event)'>"+item.name+"</a></div></div>");
					
				}else if(item.type=="4"){
					tree.append("<div class='contactbook_row' id='"+item.type+"_"+item.id+"'><div class='contact_item' ><a onclick='aClick(this,event)'>"+item.name+"</a></div></div>");
					
				}
			}
			
			for(var i in nodeData){
				var item = nodeData[i];
				var pidArray =(""+item.pid).split(",");
				for(var j in pidArray){
					moveTo(item.id,item.type,pidArray[j]);
				}
			}
			
			for(var i in nodeData){
				var item = nodeData[i];
				checkSub(item);
			}
		}
		
		function checkSub(item){
			var count = $("#"+item.type+"_"+item.id).children().size();
			if(count < 2){
				$("#"+item.type+"_"+item.id).find("a").addClass("leaf");
			}
		}
		
		function moveTo(id,type,pid){
			if(type == 1){
				pid = "1_"+pid;
			}else{
				pid = "4_"+pid;
			}
			if($("#"+pid)){
				if($("#"+type+"_"+id).parent().attr("id")=="tree"){
					$("#"+type+"_"+id).appendTo($("#"+pid));
				}else{
					$("#"+type+"_"+id).clone().appendTo($("#"+pid));
				}
			}
		}
		
		
	</script>

	</script>
</body>
</html>